Inside Macintosh: Macintosh Toolbox Essentials

Previous | Chapter Top | Chapter Contents | Next

The Event Record

When your application uses an Event Manager function to retrieve an event, the Event Manager returns information about the retrieved event in an event record structure, which is a structure of type EventRecord .

struct EventRecord {                        /* event record */
    EventKind           what;           /* event code */
    UInt32              message;        /* event message */
    UInt32              when;           /* ticks since startup */
    Point               where;          /* mouse location */
    EventModifiers      modifiers;      /* modifier flags */
    };
typedef struct EventRecord EventRecord;
what
The kind of event received. The Event Manager specifies the kind of event with one of the values defined by the EventKind enumeration (Event Kinds) .
message
Additional information associated with the event. The interpretation of this information depends on the event type. The contents of the message field for each event type are summarized here:

 

Event type

Event message

 

null, mouse-up,
mouse-down

Undefined.

 

key-up, key-down, auto-key

The low-order word contains the character code and virtual key code, which you can access with the constants charCodeMask and keyCodeMask , respectively. For Apple Desktop Bus (ADB) keyboards, the low byte of the high-order word contains the ADB address of the keyboard where the keyboard event occurred. The high byte of the high-order word is reserved.

 

update, activate

Pointer to the window to update, activate, or deactivate.

 

disk-inserted

Drive number in low-order word, File Manager result code in high-order word.

 

resume

The suspendResumeMessage enumerator in bits 24-31 and a 1 (the resumeFlag enumerator) in bit 0 indicate the event is a resume event. Bit 1 contains a 1 (the convertClipBoardFlag enumerator) if Clipboard conversion is required, and bits 2-23 are reserved.

 

suspend

The suspendResumeMessage enumerator in bits 24-31 and a 0 in bit 0 to indicate the event is a suspend event. Bit 1 is undefined, and bits 2-23 are reserved.

 

mouse-moved

The mouseMovedMessage enumerator in bits 24-31. Bits 2-23 are reserved, and bit 0 and bit 1 are undefined.

 

high-level

Class of events to which the high-level event belongs. The message and where fields of a high-level event define the specific type of high-level event received.

when
The when field indicates the time when the event was posted (in ticks since system startup).
where
For low-level events and operating-system events, the where field contains the location of the cursor at the time the event was posted (in global coordinates).
For high-level events, the where field contains a second event specifier, the event ID. The event ID defines the particular type of event within the class of events defined by the message field of the high-level event. For high-level events, you should interpret the where field as having the data type OSType , not Point .
modifiers
The modifiers field contains information about the state of the modifier keys and the mouse button at the time the event was posted. For activate events, this field also indicates whether the window should be activated or deactivated. In System 7 it also indicates whether the mouse-down event caused your application to switch to the foreground.
Each of the modifier keys is represented by a specific bit in the modifiers field of the event record structure. The modifier keys include the Option, Command, Caps Lock, Control, and Shift keys. If your application attaches special meaning to any of these keys in combination with other keys or when the mouse button is down, you can test the state of the modifiers field to determine the action your application should take. For example, you can use this information to determine whether the user pressed the Command key and another key to make a menu choice.

© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next